<template>
    <div>
        <p>用户名：<input type="text" v-model="username"></p>
        <p>密码：<input type="password" v-model="password"></p>
        <p><button @click="login()">登录</button></p>
    </div>
</template>

<script>
import axios from 'axios'
export default {
    name:'UserLogin',
    data() {
        return {
            username:'',
            password:'',
        }
    },
    methods: {
        login(){
            let formdata =new FormData()
            formdata.append('user_name',this.username)
            formdata.append('password',this.password)

            axios({
                url:'http://127.0.0.1:8000/app01/login',
                method:'post',
                data:formdata
            }).then(res=>{
                console.log(res.data)
                if(res.data.code==200){
                    sessionStorage.setItem('user_id',res.data.user_id)
                    sessionStorage.setItem('username',res.data.username)
                    this.$router.push({path:'Showgoods'})
                }else{
                    alert('登陆失败')
                }
            })
        }
    },
    created() {

    }
}
</script>

<style scoped>

</style>
